import { fileURLToPath, URL } from 'node:url'

import { defineConfig } from 'vite'
import vue from '@vitejs/plugin-vue'
import AutoImport from 'unplugin-auto-import/vite'
import Components from 'unplugin-vue-components/vite'
import { ElementPlusResolver } from 'unplugin-vue-components/resolvers'

// https://vitejs.dev/config/
export default defineConfig({
  define: {
    __VUE_PROD_HYDRATION_MISMATCH_DETAILS__: 'true'
  },
  server: {
    // 前端服务器端口(中转服务器)
    host: 'localhost',
    port: 8080,
    proxy: {
      // 通过代理实现跨域,与localhost:8080搭理这个地址
      '/api': {
        //作为替换的路径
        target: 'http://localhost:3000', // 表示要替换的服务器地址
        changeOrigin: true, //开启代理,允许跨域请求数据
        secure: false //https接口,需要配置这个参数
      }
    }
  },
  plugins: [
    vue(),
    AutoImport({
      resolvers: [ElementPlusResolver()]
    }),
    Components({
      resolvers: [ElementPlusResolver()]
    })
  ],
  resolve: {
    alias: {
      '@': fileURLToPath(new URL('./src', import.meta.url))
    }
  }
})
